package de.kiltz.foo.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import de.kiltz.foo.domain.Foo;

public class FooDAOImpl extends HibernateDaoSupport implements FooDAO
{

	@Override
	public List<Foo> getByText(String txt) throws Exception {
		
		// Volltextsuche
		txt = "%"+txt+"%";
        Query query = getSession()
                .createQuery("from Foo f where " +
                        "f.text like :txt");
        query.setString("txt", txt);
        return query.list();
	}

    public void delete(Foo o) throws Exception
    {
        getHibernateTemplate().delete(o);
    }

    public List<Foo> getAll() throws Exception
    {
        Query query = getSession()
                .createQuery("from Foo");
        return query.list();
    }

    public Foo getById(Integer id) throws Exception
    {
        return (Foo) getHibernateTemplate().get(Foo.class, id);
    }

    public Foo save(Foo o) throws Exception
    {
        getHibernateTemplate().save(o);
        return o;
    }

    public void update(Foo o) throws Exception
    {
        getHibernateTemplate().update(o);
    }


}
